package com.example.javaagent;

import com.sun.tools.attach.AgentInitializationException;
import com.sun.tools.attach.AgentLoadException;
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) {
//        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        try {
//            String pid = bufferedReader.readLine();
//            System.out.println("pid:"+pid);
            VirtualMachine virtualMachine = VirtualMachine.attach("35624");
            virtualMachine.loadAgent("/Users/shanchong/work/project/javaagent/target/java-agent.jar","/Users/shanchong/work/project/demo/target/classes/com/example/javaagent/Main.class");
            virtualMachine.detach();
        } catch (AttachNotSupportedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (AgentLoadException e) {
            e.printStackTrace();
        } catch (AgentInitializationException e) {
            e.printStackTrace();
        }
    }

}
